<template>
	<view class="page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<pageTxt>
			<z-paging ref="paging" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<view class="navbar-box">
						<u-navbar :title="formCustomer.admin_id ? '编辑客户' : '添加客户'" :autoBack="true" :fixed="false"></u-navbar>
					</view>
				</template>
				<view class="add-content ios">
					<u--form labelPosition="top" :model="formCustomer" ref="uForm" labelWidth="auto">
						<view class="form-box">
							<u-form-item labelPosition="top" labelWidth="100%" label="客户头像" borderBottom>
								<file-upload :filesList="formCustomer.imgFileOld" :count="1" :type="1" @afterRead="afterRead" @delete="deletePic"></file-upload>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" required label="客户名称" borderBottom>
								<u--input
									placeholder="客户名称"
									inputAlign="left"
									v-model="formCustomer.name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" required label="手机号" borderBottom>
								<u--input
									placeholder="手机号"
									inputAlign="left"
									maxlength="11"
									v-model="formCustomer.phone"
									border="none"
									color="#000000"
									type="digit"
									fontSize="28rpx"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" required label="客户类型" borderBottom @click="cascaderFunc('customer_type_name')">
								<u--input
									placeholder="客户类型"
									inputAlign="left"
									v-model="formCustomer.customer_type_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" required label="客户性别" borderBottom>
								<u-radio-group v-model="formCustomer.customer_sex" placement="row">
									<u-radio :label="item.label" :name="item.value" v-for="(item, index) in customerSexList" :key="index"></u-radio>
								</u-radio-group>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="客户年龄" borderBottom>
								<u--input
									placeholder="客户年龄"
									inputAlign="left"
									v-model="formCustomer.customer_age"
									border="none"
									color="#000000"
									type="digit"
									fontSize="28rpx"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" required label="客户业务区域" borderBottom @click="cascaderFunc('business_area_id')">
								<u--input
									placeholder="客户业务区域"
									inputAlign="left"
									v-model="formCustomer.business_area_id.names.join('/')"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" required label="品牌" borderBottom @click="cascaderFunc('brand_id_name')">
								<u--input
									placeholder="品牌"
									inputAlign="left"
									v-model="formCustomer.brand_id_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="渠道来源" borderBottom @click="cascaderFunc('source_name')">
								<u--input
									placeholder="渠道来源"
									inputAlign="left"
									v-model="formCustomer.source_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="对客关注度" borderBottom @click="cascaderFunc('customer_attention_name')">
								<u--input
									placeholder="对客关注度"
									inputAlign="left"
									v-model="formCustomer.customer_attention_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="客户身份" borderBottom @click="cascaderFunc('customer_identity_name')">
								<u--input
									placeholder="客户身份"
									inputAlign="left"
									v-model="formCustomer.customer_identity_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="客户态度" borderBottom @click="cascaderFunc('customer_attitude_name')">
								<u--input
									placeholder="客户态度"
									inputAlign="left"
									v-model="formCustomer.customer_attitude_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="年度开店计划" borderBottom @click="cascaderFunc('annual_store_opening_plan_name')">
								<u--input
									placeholder="年度开店计划"
									inputAlign="left"
									v-model="formCustomer.annual_store_opening_plan_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="目前经营品牌" borderBottom>
								<u--input
									placeholder="目前经营品牌"
									inputAlign="left"
									v-model="formCustomer.current_operating_brand"
									border="none"
									color="#000000"
									fontSize="28rpx"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="次社会关系" borderBottom @click="cascaderFunc('secondary_social_relations_name')">
								<u--input
									placeholder="次社会关系"
									inputAlign="left"
									v-model="formCustomer.secondary_social_relations_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="投资能力" borderBottom @click="cascaderFunc('investment_capability_name')">
								<u--input
									placeholder="投资能力"
									inputAlign="left"
									v-model="formCustomer.investment_capability_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="会员类型" borderBottom @click="cascaderFunc('member_type_name')">
								<u--input
									placeholder="会员类型"
									inputAlign="left"
									v-model="formCustomer.member_type_name"
									border="none"
									color="#000000"
									fontSize="28rpx"
									disabled
									disabledColor="#ffffff"
									suffixIcon="arrow-right"
									suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="备注" borderBottom>
								<u--input
									placeholder="备注"
									inputAlign="left"
									v-model="formCustomer.remark"
									border="none"
									color="#000000"
									fontSize="28rpx"
									placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
								></u--input>
							</u-form-item>
						</view>
						<!-- 合伙狼 -->
						<view class="add-box">
							<template v-for="(item, index) in formCustomer.partner_list">
								<view class="title-box flex ac jb" :key="index">
									<view class="title">联系人{{ index + 1 }}</view>
									<view class="del" @click="delSpecsFunc(index)">删除</view>
								</view>
								<view class="form-box" :key="index">
									<u-form-item labelPosition="top" labelWidth="100%" required label="联系人名称" borderBottom>
										<u--input
											placeholder="联系人名称"
											inputAlign="left"
											v-model="item.customer_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" required label="联系方式" borderBottom>
										<u--input
											placeholder="联系方式"
											inputAlign="left"
											maxlength="11"
											v-model="item.customer_phone"
											border="none"
											color="#000000"
											type="digit"
											fontSize="28rpx"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="客户身份" borderBottom @click="cascaderFunc('customer_identity_name', index)">
										<u--input
											placeholder="客户身份"
											inputAlign="left"
											v-model="item.customer_identity_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											disabled
											disabledColor="#ffffff"
											suffixIcon="arrow-right"
											suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="对客关注度" borderBottom @click="cascaderFunc('customer_attention_name', index)">
										<u--input
											placeholder="对客关注度"
											inputAlign="left"
											v-model="item.customer_attention_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											disabled
											disabledColor="#ffffff"
											suffixIcon="arrow-right"
											suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="客户态度" borderBottom @click="cascaderFunc('customer_attitude_name', index)">
										<u--input
											placeholder="客户态度"
											inputAlign="left"
											v-model="item.customer_attitude_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											disabled
											disabledColor="#ffffff"
											suffixIcon="arrow-right"
											suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="年度开店计划" borderBottom @click="cascaderFunc('annual_store_opening_plan_name', index)">
										<u--input
											placeholder="年度开店计划"
											inputAlign="left"
											v-model="item.annual_store_opening_plan_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											disabled
											disabledColor="#ffffff"
											suffixIcon="arrow-right"
											suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="目前经营品牌" borderBottom>
										<u--input
											placeholder="目前经营品牌"
											inputAlign="left"
											v-model="item.current_operating_brand"
											border="none"
											color="#000000"
											type="digit"
											fontSize="28rpx"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="次社会关系" borderBottom @click="cascaderFunc('secondary_social_relations_name', index)">
										<u--input
											placeholder="次社会关系"
											inputAlign="left"
											v-model="item.secondary_social_relations_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											disabled
											disabledColor="#ffffff"
											suffixIcon="arrow-right"
											suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="投资能力" borderBottom @click="cascaderFunc('investment_capability_name', index)">
										<u--input
											placeholder="投资能力"
											inputAlign="left"
											v-model="item.investment_capability_name"
											border="none"
											color="#000000"
											fontSize="28rpx"
											disabled
											disabledColor="#ffffff"
											suffixIcon="arrow-right"
											suffixIconStyle="color: #727272;font-size:24rpx;font-weight:500;"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
									<u-form-item labelPosition="top" labelWidth="100%" label="备注" borderBottom>
										<u--input
											placeholder="备注"
											inputAlign="left"
											v-model="item.remark"
											border="none"
											color="#000000"
											fontSize="28rpx"
											placeholderStyle="font-weight: 400;font-size: 28rpx;color: #B1B1B0;"
										></u--input>
									</u-form-item>
								</view>
							</template>
							<!-- 添加 -->
							<u-button
								@click="addSpecsFunc"
								icon="plus"
								iconColor="#3B75FF"
								text="新增联系人"
								customStyle="font-size:28rpx;color:#3B75FF;border:none;border-radius: 12rpx;"
							></u-button>
						</view>
					</u--form>
				</view>
				<view class="footer ios">
					<u-button
						text="提交"
						@click="submit"
						customStyle="width: 702rpx;height: 88rpx;background: #3B75FF;border-radius: 16rpx;font-weight: 500;font-size: 28rpx;color: #FFFFFF;margin:20rpx 24rpx;"
					></u-button>
				</view>
			</z-paging>
			<!-- 客户类型 -->
			<u-picker
				ref="customerTypeShow"
				title="客户类型"
				closeOnClickOverlay
				:show="customerTypeShow"
				:columns="[customerTypeList]"
				@confirm="confirmFunc($event, 'customerTypeShow')"
				@cancel="closeFunc('customerTypeShow')"
				@close="closeFunc('customerTypeShow')"
				keyName="label"
			></u-picker>
			<!-- 客户业务区域 -->
			<bottom-select ref="userSelect" :fetch-data="wxGetAreaList" v-model="formCustomer.business_area_id" label-key="name" :multiple="true" value-key="id" />
			<!-- 品牌 -->
			<u-picker
				ref="brandShow"
				title="品牌"
				closeOnClickOverlay
				:show="brandShow"
				:columns="[brandList]"
				@confirm="confirmFunc($event, 'brandShow')"
				@cancel="closeFunc('brandShow')"
				@close="closeFunc('brandShow')"
				keyName="name"
			></u-picker>
			<!-- 渠道来源 -->
			<u-picker
				ref="sourceShow"
				title="渠道来源"
				closeOnClickOverlay
				:show="sourceShow"
				:columns="[sourceList]"
				@confirm="confirmFunc($event, 'sourceShow')"
				@cancel="closeFunc('sourceShow')"
				@close="closeFunc('sourceShow')"
				keyName="label"
			></u-picker>
			<!-- 对客关注度 -->
			<u-picker
				ref="attentionShow"
				title="对客关注度"
				closeOnClickOverlay
				:show="attentionShow"
				:columns="[attentionList]"
				@confirm="confirmFunc($event, 'attentionShow')"
				@cancel="closeFunc('attentionShow')"
				@close="closeFunc('attentionShow')"
				keyName="label"
			></u-picker>
			<!-- 客户身份 -->
			<u-picker
				ref="identityShow"
				title="客户身份"
				closeOnClickOverlay
				:show="identityShow"
				:columns="[identityList]"
				@confirm="confirmFunc($event, 'identityShow')"
				@cancel="closeFunc('identityShow')"
				@close="closeFunc('identityShow')"
				keyName="label"
			></u-picker>
			<!-- 客户态度 -->
			<u-picker
				ref="attitudeShow"
				title="客户态度"
				closeOnClickOverlay
				:show="attitudeShow"
				:columns="[attitudeList]"
				@confirm="confirmFunc($event, 'attitudeShow')"
				@cancel="closeFunc('attitudeShow')"
				@close="closeFunc('attitudeShow')"
				keyName="label"
			></u-picker>
			<!-- 年度开店计划 -->
			<u-picker
				ref="annualStoreOpeningPlanShow"
				title="年度开店计划"
				closeOnClickOverlay
				:show="annualStoreOpeningPlanShow"
				:columns="[annualStoreOpeningPlan]"
				@confirm="confirmFunc($event, 'annualStoreOpeningPlanShow')"
				@cancel="closeFunc('annualStoreOpeningPlanShow')"
				@close="closeFunc('annualStoreOpeningPlanShow')"
				keyName="label"
			></u-picker>
			<!-- 次社会关系 -->
			<u-picker
				ref="secondarySocialRelationsShow"
				title="次社会关系"
				closeOnClickOverlay
				:show="secondarySocialRelationsShow"
				:columns="[secondarySocialRelations]"
				@confirm="confirmFunc($event, 'secondarySocialRelationsShow')"
				@cancel="closeFunc('secondarySocialRelationsShow')"
				@close="closeFunc('secondarySocialRelationsShow')"
				keyName="label"
			></u-picker>
			<!-- 投资能力 -->
			<u-picker
				ref="investmentCapabilityShow"
				title="投资能力"
				closeOnClickOverlay
				:show="investmentCapabilityShow"
				:columns="[investmentCapabilityList]"
				@confirm="confirmFunc($event, 'investmentCapabilityShow')"
				@cancel="closeFunc('investmentCapabilityShow')"
				@close="closeFunc('investmentCapabilityShow')"
				keyName="label"
			></u-picker>
			<!-- 会员类型 -->
			<u-picker
				ref="memberTypeShow"
				title="会员类型"
				closeOnClickOverlay
				:show="memberTypeShow"
				:columns="[memberTypeList]"
				@confirm="confirmFunc($event, 'memberTypeShow')"
				@cancel="closeFunc('memberTypeShow')"
				@close="closeFunc('memberTypeShow')"
				keyName="label"
			></u-picker>
		</pageTxt>
	</view>
</template>

<script>
export default {
	data() {
		return {
			loading: false,
			customerTypeShow: false, //客户类型弹窗
			brandShow: false, //品牌弹窗
			sourceShow: false, //渠道来源弹窗
			attentionShow: false, //对客关注度弹窗
			identityShow: false, //客户身份弹窗
			attitudeShow: false, //客户态度弹窗
			annualStoreOpeningPlanShow: false, //年度开店计划弹窗
			secondarySocialRelationsShow: false, //次社会关系弹窗
			investmentCapabilityShow: false, //投资能力弹窗
			memberTypeShow: false, //会员类型弹窗

			formCustomer: {
				admin_id: '',
				imgFile: [],
				imgFileOld: [],
				name: '',
				phone: '',
				password: '',
				brand_id: '',
				brand_id_name: '',
				business_area_id: {
					ids: [],
					names: []
				},
				customer_type: '',
				customer_type_name: '',
				customer_sex: 1,
				customer_age: '',
				customer_identity: '',
				customer_identity_name: '',
				customer_attention: '',
				customer_attention_name: '',
				customer_attitude: '',
				customer_attitude_name: '',
				current_operating_brand: '',
				secondary_social_relations: '',
				secondary_social_relations_name: '',
				investment_capability: '',
				investment_capability_name: '',
				annual_store_opening_plan: '',
				annual_store_opening_plan_name: '',
				member_type: '',
				member_type_name: '',
				remark: '',
				source: '',
				source_name: '',
				partner_list: [
					// {
					// 	customer_name: '',
					// 	customer_phone: '',
					// 	customer_identity: '',
					// 	customer_identity_name: '',
					// 	customer_attention: '',
					// 	customer_attention_name: '',
					// 	customer_attitude: '',
					// 	customer_attitude_name: '',
					// 	current_operating_brand: '',
					// 	secondary_social_relations: '',
					// 	secondary_social_relations_name: '',
					// 	investment_capability: '',
					// 	investment_capability_name: '',
					// 	annual_store_opening_plan: '',
					// 	annual_store_opening_plan_name: '',
					// 	remark: ''
					// }
				] //合伙人列表
			},
			attentionList: [
				{
					label: '持续重点关注',
					value: 1
				},
				{
					label: '持续关注',
					value: 2
				},
				{
					label: '定期关注',
					value: 3
				},
				{
					label: '不定期关注',
					value: 4
				},
				{
					label: '一般关注',
					value: 5
				}
			],
			attitudeList: [
				{
					label: '积极主动',
					value: 1
				},
				{
					label: '沟通顺畅',
					value: 2
				},
				{
					label: '敷衍了事',
					value: 3
				},
				{
					label: '拒不配合',
					value: 4
				}
			],
			identityList: [
				{
					label: '老板',
					value: 1
				},
				{
					label: '合伙人',
					value: 2
				},
				{
					label: '项目负责人',
					value: 3
				},
				{
					label: '签约人',
					value: 4
				}
			],
			customerTypeList: [
				{
					label: 'VIP客户',
					value: 1
				},
				{
					label: '优质客户',
					value: 2
				},
				{
					label: '普通老客户',
					value: 3
				},
				{
					label: '优质新客户',
					value: 4
				},
				{
					label: '普通新客户',
					value: 5
				}
			],
			investmentCapabilityList: [
				{
					label: '100w以下',
					value: 1
				},
				{
					label: '100-500w',
					value: 2
				},
				{
					label: '500-1000w',
					value: 3
				},
				{
					label: '1000w以上',
					value: 4
				}
			],
			annualStoreOpeningPlan: [
				{
					label: '不连续且少量开店',
					value: 1
				},
				{
					label: '不连续且大量开店',
					value: 2
				},
				{
					label: '持续且少量开店',
					value: 3
				},
				{
					label: '持续且大量开店',
					value: 4
				}
			],
			customerSexList: [
				{
					label: '男',
					value: 1
				},
				{
					label: '女',
					value: 2
				}
			],
			secondarySocialRelations: [
				{
					label: '品牌方关系户',
					value: 1
				},
				{
					label: '我司关系户',
					value: 2
				},
				{
					label: '政府关系户',
					value: 3
				},
				{
					label: '一般关系',
					value: 4
				}
			],
			sourceList: [
				{
					label: '品牌客户',
					value: 1
				},
				{
					label: '电销',
					value: 2
				},
				{
					label: '展会',
					value: 3
				},
				{
					label: '转介绍',
					value: 4
				},
				{
					label: '其他',
					value: 5
				}
			],
			memberTypeList: [
				{
					label: '新会员',
					value: 1
				},
				{
					label: 'VIP会员',
					value: 2
				},
				{
					label: 'VVIP会员',
					value: 3
				}
			],
			brandList: [],
			partnerIndex: '' //联系人index
		};
	},
	async onLoad(option) {
		let brandList = await this.$Apipc.getBrandList({
			page: 1,
			num: 999
		});
		this.brandList = brandList.data.list;
		if (option.id) {
			this.getUserDetail(option.id);
		}
	},
	methods: {
		async wxGetAreaList(data) {
			// 施工阶段
			let res = await this.$Api.wxGetAreaList(data);
			console.log(res, '省市区');
			return res;
		},
		// picker 弹窗打开
		cascaderFunc(type, index) {
			this.partnerIndex = index === undefined ? '' : index;
			switch (type) {
				case 'customer_type_name':
					let customerTypeIndex = this.customerTypeList.findIndex((item) => {
						return item.value == this.formCustomer.customer_type;
					});
					this.$refs.customerTypeShow.setIndexs([customerTypeIndex == -1 ? 0 : customerTypeIndex], true);
					this.customerTypeShow = true;
					break;
				case 'business_area_id':
					this.$refs.userSelect.open();
					break;
				case 'brand_id_name':
					let brandIndex = this.brandList.findIndex((item) => {
						return item.id == this.formCustomer.brand_id;
					});
					this.$refs.brandShow.setIndexs([brandIndex == -1 ? 0 : brandIndex], true);
					this.brandShow = true;
					break;
				case 'source_name':
					let sourceIndex = this.sourceList.findIndex((item) => {
						return item.value == this.formCustomer.source;
					});
					this.$refs.sourceShow.setIndexs([sourceIndex == -1 ? 0 : sourceIndex], true);
					this.sourceShow = true;
					break;
				case 'customer_attention_name':
					let attentionIndex = -1;
					if (index === undefined) {
						// 客户
						attentionIndex = this.attentionList.findIndex((item) => {
							return item.value == this.formCustomer.customer_attention;
						});
					} else {
						// 联系人
						attentionIndex = this.attentionList.findIndex((item) => {
							return item.value == this.formCustomer.partner_list[0].customer_attention;
						});
					}
					this.$refs.attentionShow.setIndexs([attentionIndex == -1 ? 0 : attentionIndex], true);
					this.attentionShow = true;
					break;
				case 'customer_identity_name':
					let identityIndex = -1;
					if (index === undefined) {
						// 客户
						identityIndex = this.identityList.findIndex((item) => {
							return item.value == this.formCustomer.customer_identity;
						});
					} else {
						// 联系人
						identityIndex = this.identityList.findIndex((item) => {
							return item.value == this.formCustomer.partner_list[index].customer_identity;
						});
					}
					this.$refs.identityShow.setIndexs([identityIndex == -1 ? 0 : identityIndex], true);
					this.identityShow = true;
					break;
				case 'customer_attitude_name':
					let attitudeIndex = -1;
					if (index === undefined) {
						// 客户
						attitudeIndex = this.attitudeList.findIndex((item) => {
							return item.value == this.formCustomer.customer_attitude;
						});
					} else {
						// 联系人
						attitudeIndex = this.attitudeList.findIndex((item) => {
							return item.value == this.formCustomer.partner_list[0].customer_attitude;
						});
					}
					this.$refs.attitudeShow.setIndexs([attitudeIndex == -1 ? 0 : attitudeIndex], true);
					this.attitudeShow = true;
					break;
				case 'annual_store_opening_plan_name':
					let annualStoreOpeningPlanIndex = -1;
					if (index === undefined) {
						annualStoreOpeningPlanIndex = this.annualStoreOpeningPlan.findIndex((item) => {
							return item.value == this.formCustomer.annual_store_opening_plan;
						});
					} else {
						annualStoreOpeningPlanIndex = this.annualStoreOpeningPlan.findIndex((item) => {
							return item.value == this.formCustomer.partner_list[0].annual_store_opening_plan;
						});
					}
					this.$refs.annualStoreOpeningPlanShow.setIndexs([annualStoreOpeningPlanIndex == -1 ? 0 : annualStoreOpeningPlanIndex], true);
					this.annualStoreOpeningPlanShow = true;
					break;
				case 'secondary_social_relations_name':
					let secondarySocialRelationsIndex = -1;
					if (index === undefined) {
						secondarySocialRelationsIndex = this.secondarySocialRelations.findIndex((item) => {
							return item.value == this.formCustomer.secondary_social_relations;
						});
					} else {
						secondarySocialRelationsIndex = this.secondarySocialRelations.findIndex((item) => {
							return item.value == this.formCustomer.partner_list[0].secondary_social_relations;
						});
					}
					this.$refs.secondarySocialRelationsShow.setIndexs([secondarySocialRelationsIndex == -1 ? 0 : secondarySocialRelationsIndex], true);
					this.secondarySocialRelationsShow = true;
					break;
				case 'investment_capability_name':
					let investmentCapabilityIndex = -1;
					if (index === undefined) {
						investmentCapabilityIndex = this.investmentCapabilityList.findIndex((item) => {
							return item.value == this.formCustomer.investment_capability;
						});
					} else {
						investmentCapabilityIndex = this.investmentCapabilityList.findIndex((item) => {
							return item.value == this.formCustomer.partner_list[0].investment_capability;
						});
					}
					this.$refs.investmentCapabilityShow.setIndexs([investmentCapabilityIndex == -1 ? 0 : investmentCapabilityIndex], true);
					this.investmentCapabilityShow = true;
					break;
				case 'member_type_name':
					let memberTypeIndex = this.memberTypeList.findIndex((item) => {
						return item.value == this.formCustomer.member_type;
					});
					this.$refs.memberTypeShow.setIndexs([memberTypeIndex == -1 ? 0 : memberTypeIndex], true);
					this.memberTypeShow = true;
					break;

				default:
			}
		},
		// picker 弹窗关闭
		closeFunc(type) {
			switch (type) {
				case 'customerTypeShow':
					this.customerTypeShow = false;
					break;
				case 'brandShow':
					this.brandShow = false;
					break;
				case 'sourceShow':
					this.sourceShow = false;
					break;
				case 'attentionShow':
					this.attentionShow = false;
					break;
				case 'identityShow':
					this.identityShow = false;
					break;
				case 'attitudeShow':
					this.attitudeShow = false;
					break;
				case 'annualStoreOpeningPlanShow':
					this.annualStoreOpeningPlanShow = false;
					break;
				case 'secondarySocialRelationsShow':
					this.secondarySocialRelationsShow = false;
					break;
				case 'investmentCapabilityShow':
					this.investmentCapabilityShow = false;
					break;
				case 'memberTypeShow':
					this.memberTypeShow = false;
					break;

				default:
			}
		},
		// picker 弹窗选择
		confirmFunc(e, type) {
			console.log(e);
			let partnerIndex = this.partnerIndex;
			switch (type) {
				case 'customerTypeShow':
					this.formCustomer.customer_type = e.value[0].value;
					this.formCustomer.customer_type_name = e.value[0].label;
					this.customerTypeShow = false;
					break;
				case 'brandShow':
					this.formCustomer.brand_id = e.value[0].id;
					this.formCustomer.brand_id_name = e.value[0].name;
					this.brandShow = false;
					break;
				case 'sourceShow':
					this.formCustomer.source = e.value[0].value;
					this.formCustomer.source_name = e.value[0].label;
					this.sourceShow = false;
					break;
				case 'attentionShow':
					if (partnerIndex === '') {
						this.formCustomer.customer_attention = e.value[0].value;
						this.formCustomer.customer_attention_name = e.value[0].label;
					} else {
						this.formCustomer.partner_list[partnerIndex].customer_attention = e.value[0].value;
						this.formCustomer.partner_list[partnerIndex].customer_attention_name = e.value[0].label;
					}
					this.attentionShow = false;
					break;
				case 'identityShow':
					if (partnerIndex === '') {
						this.formCustomer.customer_identity = e.value[0].value;
						this.formCustomer.customer_identity_name = e.value[0].label;
					} else {
						this.formCustomer.partner_list[partnerIndex].customer_identity = e.value[0].value;
						this.formCustomer.partner_list[partnerIndex].customer_identity_name = e.value[0].label;
					}
					this.identityShow = false;
					break;
				case 'attitudeShow':
					if (partnerIndex === '') {
						this.formCustomer.customer_attitude = e.value[0].value;
						this.formCustomer.customer_attitude_name = e.value[0].label;
					} else {
						this.formCustomer.partner_list[partnerIndex].customer_attitude = e.value[0].value;
						this.formCustomer.partner_list[partnerIndex].customer_attitude_name = e.value[0].label;
					}
					this.attitudeShow = false;
					break;
				case 'annualStoreOpeningPlanShow':
					if (partnerIndex === '') {
						this.formCustomer.annual_store_opening_plan = e.value[0].value;
						this.formCustomer.annual_store_opening_plan_name = e.value[0].label;
					} else {
						this.formCustomer.partner_list[partnerIndex].annual_store_opening_plan = e.value[0].value;
						this.formCustomer.partner_list[partnerIndex].annual_store_opening_plan_name = e.value[0].label;
					}
					this.annualStoreOpeningPlanShow = false;
					break;
				case 'secondarySocialRelationsShow':
					if (partnerIndex === '') {
						this.formCustomer.secondary_social_relations = e.value[0].value;
						this.formCustomer.secondary_social_relations_name = e.value[0].label;
					} else {
						this.formCustomer.partner_list[partnerIndex].secondary_social_relations = e.value[0].value;
						this.formCustomer.partner_list[partnerIndex].secondary_social_relations_name = e.value[0].label;
					}
					this.secondarySocialRelationsShow = false;
					break;
				case 'investmentCapabilityShow':
					if (partnerIndex === '') {
						this.formCustomer.investment_capability = e.value[0].value;
						this.formCustomer.investment_capability_name = e.value[0].label;
					} else {
						this.formCustomer.partner_list[partnerIndex].investment_capability = e.value[0].value;
						this.formCustomer.partner_list[partnerIndex].investment_capability_name = e.value[0].label;
					}
					this.investmentCapabilityShow = false;
					break;
				case 'memberTypeShow':
					this.formCustomer.member_type = e.value[0].value;
					this.formCustomer.member_type_name = e.value[0].label;
					this.memberTypeShow = false;
					break;

				default:
			}
		},
		afterRead(files) {
			console.log(files);
			files.map((item) => {
				let obj = {
					url: item.url
				};
				this.formCustomer.imgFile.push(obj);
			});
		},
		deletePic(e) {
			this.formCustomer.imgFile.splice(e.index, 1);
		},
		// 添加联系人
		addSpecsFunc() {
			this.formCustomer.partner_list.push({
				customer_name: '',
				customer_phone: '',
				customer_identity: '',
				customer_identity_name: '',
				customer_attention: '',
				customer_attention_name: '',
				customer_attitude: '',
				customer_attitude_name: '',
				current_operating_brand: '',
				secondary_social_relations: '',
				secondary_social_relations_name: '',
				investment_capability: '',
				investment_capability_name: '',
				annual_store_opening_plan: '',
				annual_store_opening_plan_name: '',
				remark: ''
			});
		},
		// 删除联系人
		delSpecsFunc(index) {
			this.formCustomer.partner_list.splice(index, 1);
		},
		// 提交数据判空
		dataIsNullFunc() {
			let formCustomer = this.formCustomer;
			if (!formCustomer.name) {
				uni.showToast({
					title: '请输入客户名称',
					icon: 'error'
				});
				return false;
			}
			if (!uni.$u.test.mobile(formCustomer.phone)) {
				uni.showToast({
					title: '请输入客户正确手机号',
					icon: 'error'
				});
				return false;
			}
			if (!formCustomer.customer_type) {
				uni.showToast({
					title: '请输入客户类型',
					icon: 'error'
				});
				return false;
			}
			if (!formCustomer.customer_sex) {
				uni.showToast({
					title: '请选择客户性别',
					icon: 'error'
				});
				return false;
			}
			if (!formCustomer.business_area_id.names.length) {
				uni.showToast({
					title: '请选择客户业务区域',
					icon: 'error'
				});
				return false;
			}
			if (!formCustomer.brand_id_name) {
				uni.showToast({
					title: '请选择客户品牌',
					icon: 'error'
				});
				return false;
			}
			for (let i = 0; i < formCustomer.partner_list.length; i++) {
				if (!formCustomer.partner_list[i].customer_name) {
					uni.showToast({
						title: `请输入“联系人${i + 1}”名称`,
						icon: 'error'
					});
					return false;
				}
				if (!uni.$u.test.mobile(formCustomer.partner_list[i].customer_phone)) {
					uni.showToast({
						title: `请输入“联系人${i + 1}”正确联系方式`,
						icon: 'error'
					});
					return false;
				}
			}
			return true;
		},
		async submit() {
			let formCustomer = this.formCustomer;
			console.log(formCustomer);
			if (!this.dataIsNullFunc()) return;
			let partner_list = JSON.parse(JSON.stringify(formCustomer.partner_list));
			partner_list.forEach((item) => {
				item.annual_store_opening_plan = item.annual_store_opening_plan || 0;
				item.current_operating_brand = item.current_operating_brand || '';
				item.customer_attention = item.customer_attention || 0;
				item.customer_attitude = item.customer_attitude || 0;
				item.customer_identity = item.customer_identity || 0;
				item.investment_capability = item.investment_capability || 0;
				item.secondary_social_relations = item.secondary_social_relations || 0;
			});
			let data = {
				member_type: formCustomer.member_type,

				identity: 4,
				name: formCustomer.name,
				phone: formCustomer.phone,
				password: '',
				province_id: 0,
				city_id: 0,
				county_id: 0,
				role_id: 0,
				position_id: 0,
				brand_id: formCustomer.brand_id || 0,
				business_area: formCustomer.business_area_id.names,
				business_area_id: formCustomer.business_area_id.ids,
				customer_type: formCustomer.customer_type || 0,
				customer_sex: formCustomer.customer_sex || 0,
				customer_age: formCustomer.customer_age || 0,

				customer_identity: formCustomer.customer_identity || 0,
				customer_attention: formCustomer.customer_attention || 0,
				customer_attitude: formCustomer.customer_attitude || 0,
				current_operating_brand: formCustomer.current_operating_brand || '',
				secondary_social_relations: formCustomer.secondary_social_relations || 0,
				investment_capability: formCustomer.investment_capability || 0,
				annual_store_opening_plan: formCustomer.annual_store_opening_plan || 0,
				remark: formCustomer.remark,
				partner_list: partner_list,
				admin_id: formCustomer.admin_id || '',
				source: formCustomer.source
			};
			let imgFile = '';
			if (formCustomer.imgFile.length) {
				uni.showLoading({
					mask: true,
					title: '头像上传中'
				});
				imgFile = await this.$upload(formCustomer.imgFile);
				console.log(imgFile.arrResult, '头像');
				uni.hideLoading();
			}
			imgFile ? (data.image = imgFile.arrResult) : '';
			console.log(data);
			// 更新
			if (formCustomer.admin_id) {
				this.updUser(data);
				return;
			}
			this.addUser(data);
		},
		// 添加客户
		addUser(data) {
			uni.showLoading({
				mask: true,
				title: '信息提交中'
			});
			this.$Apipc.addUser(data).then((res) => {
				console.log(res, '添加客户');
				uni.hideLoading();
				if (res.code == 200) {
					var pages = getCurrentPages();
					var perPage = pages[pages.length - 2];
					perPage.$vm.$refs.customerManagement.searchFunc();
					setTimeout(() => {
						uni.navigateBack();
					}, 500);
				}
				uni.showToast({
					title: res.message,
					icon: res.code == 200 ? 'success' : 'error'
				});
			});
		},
		// 更新客户
		updUser(data) {
			uni.showLoading({
				mask: true,
				title: '信息提交中'
			});
			this.$Apipc.updUser(data).then((res) => {
				console.log(res, '更新客户');
				uni.hideLoading();
				if (res.code == 200) {
					setTimeout(() => {
						uni.navigateBack();
					}, 500);
				}
				uni.showToast({
					title: res.message,
					icon: res.code == 200 ? 'success' : 'error'
				});
			});
		},
		// 用户详情
		getUserDetail(user_id) {
			uni.showLoading({
				mask: true
			});
			this.$Apipc.getUserDetail({ user_id }).then((res) => {
				console.log(res, '用户详情');
				uni.hideLoading();
				if (res.code == 200) {
					let { data } = res;
					let business_area_id = [];
					let business_area = [];
					if (data.business_area_id) {
						data.business_area_id.split(',').forEach((item) => {
							business_area_id.push(Number(item));
						});
					}
					if (data.business_area) {
						data.business_area.split(',').forEach((item) => {
							business_area.push(item);
						});
					}
					// 客户信息匹配
					let customer_type_name = this.customerTypeList.find((item) => {
						return data.customer_type === item.value;
					});
					let customer_identity_name = this.identityList.find((item) => {
						return item.value === data.customer_identity;
					});
					let customer_attention_name = this.attentionList.find((item) => {
						return item.value === data.customer_attention;
					});
					let customer_attitude_name = this.attitudeList.find((item) => {
						return item.value == data.customer_attitude;
					});
					let secondary_social_relations_name = this.secondarySocialRelations.find((item) => {
						return item.value === data.secondary_social_relations;
					});
					let investment_capability_name = this.investmentCapabilityList.find((item) => {
						return item.value === data.investment_capability;
					});
					let annual_store_opening_plan_name = this.annualStoreOpeningPlan.find((item) => {
						return item.value === data.annual_store_opening_plan;
					});
					let member_type_name = this.memberTypeList.find((item) => {
						return item.value === data.member_type;
					});
					let source_name = this.sourceList.find((item) => {
						return item.value === data.source;
					});
					let brand_id_name = this.brandList.find((item) => {
						return data.brand_id === item.id;
					});

					// 联系人数据匹配
					data.partner_list.forEach((lItem) => {
						let customer_identity_name = this.identityList.find((item) => {
							return item.value === lItem.customer_identity;
						});
						lItem.customer_identity_name = customer_identity_name ? customer_identity_name.label : '';

						let customer_attention_name = this.attentionList.find((item) => {
							return item.value === lItem.customer_attention;
						});
						lItem.customer_attention_name = customer_attention_name ? customer_attention_name.label : '';

						let customer_attitude_name = this.attitudeList.find((item) => {
							return item.value == lItem.customer_attitude;
						});
						lItem.customer_attitude_name = customer_attitude_name ? customer_attitude_name.label : '';

						let secondary_social_relations_name = this.secondarySocialRelations.find((item) => {
							return item.value === lItem.secondary_social_relations;
						});
						lItem.secondary_social_relations_name = secondary_social_relations_name ? secondary_social_relations_name.label : '';

						let investment_capability_name = this.investmentCapabilityList.find((item) => {
							return item.value === lItem.investment_capability;
						});
						lItem.investment_capability_name = investment_capability_name ? investment_capability_name.label : '';

						let annual_store_opening_plan_name = this.annualStoreOpeningPlan.find((item) => {
							return item.value === lItem.annual_store_opening_plan;
						});
						lItem.annual_store_opening_plan_name = annual_store_opening_plan_name ? annual_store_opening_plan_name.label : '';
					});
					this.formCustomer = {
						admin_id: user_id,
						imgFile: [],
						imgFileOld: data.image
							? [
									{
										file_url: data.image,
										file_suffix: 'png'
									}
							  ]
							: [],
						name: data.name,
						phone: data.phone,
						password: '',
						brand_id: data.brand_id,
						brand_id_name: brand_id_name ? brand_id_name.name : '',
						business_area_id: {
							ids: business_area_id,
							names: business_area
						},
						customer_type: data.customer_type,
						customer_type_name: customer_type_name ? customer_type_name.label : '',
						customer_sex: data.customer_sex,
						customer_age: data.customer_age || '',
						customer_identity: data.customer_identity,
						customer_identity_name: customer_identity_name ? customer_identity_name.label : '',
						customer_attention: data.customer_attention,
						customer_attention_name: customer_attention_name ? customer_attention_name.label : '',
						customer_attitude: data.customer_attitude,
						customer_attitude_name: customer_attitude_name ? customer_attitude_name.label : '',
						current_operating_brand: data.current_operating_brand,
						secondary_social_relations: data.secondary_social_relations,
						secondary_social_relations_name: secondary_social_relations_name ? secondary_social_relations_name.label : '',
						investment_capability: data.investment_capability,
						investment_capability_name: investment_capability_name ? investment_capability_name.label : '',
						annual_store_opening_plan: data.annual_store_opening_plan,
						annual_store_opening_plan_name: annual_store_opening_plan_name ? annual_store_opening_plan_name.label : '',
						member_type: data.member_type,
						member_type_name: member_type_name ? member_type_name.label : '',
						remark: data.remark,
						source: data.source,
						source_name: source_name ? source_name.label : '',
						partner_list: data.partner_list
					};
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.add-box {
	width: 100%;
	padding: 2rpx;
	box-sizing: border-box;

	.title-box {
		width: 100%;
		padding: 10rpx 10rpx;
		box-sizing: border-box;

		.title {
			font-weight: 400;
			font-size: 26rpx;
			color: #000000;
		}

		.del {
			font-weight: 400;
			font-size: 26rpx;
			color: #3b75ff;
			text-decoration: underline;
		}
	}
}
</style>
